package com.thunder.soft.ui.activity;

import android.content.Intent;
import android.util.Log;
import android.widget.LinearLayout;

import androidx.lifecycle.Observer;

import com.just.agentweb.AgentWeb;
import com.thunder.soft.R;
import com.thunder.soft.common.base.BaseActivity;
import com.thunder.soft.common.util.ViewModelProviderHelper;
import com.thunder.soft.databinding.ActivitySystemItemDetailBinding;
import com.thunder.soft.vm.SystemItemDatailViewModel;

public class SystemItemDetailActivity extends BaseActivity<ActivitySystemItemDetailBinding> {

    private static String TAG=SystemItemDetailActivity.class.getName();
    private String url="";
    private AgentWeb agentWeb;
    private SystemItemDatailViewModel systemItemDatailViewModel;

    @Override
    protected void initData() {
        systemItemDatailViewModel = ViewModelProviderHelper.buildViewModel(this,SystemItemDatailViewModel.class);
        getLifecycle().addObserver(systemItemDatailViewModel);
        binding.setSystemItemDetailViewModel(systemItemDatailViewModel);

        Intent intent = getIntent();
        url = intent.getStringExtra("link");
        Log.e(TAG,url+"************************");
        agentWeb = AgentWeb.with(this)//传入Activity
                .setAgentWebParent(binding.root, new LinearLayout.LayoutParams(-1, -1))//传入AgentWeb 的父控件 ，如果父控件为 RelativeLayout ， 那么第二参数需要传入 RelativeLayout.LayoutParams
                .useDefaultIndicator()// 使用默认进度条
//                .defaultProgressBarColor() // 使用默认进度条颜色
//                .setReceivedTitleCallback(mCallback) //设置 Web 页面的 title 回调
                .createAgentWeb()
                .ready()
                .go(url);

        // 关闭页面
        systemItemDatailViewModel.getFinishActivity().observe(this, new Observer<Integer>() {
            @Override
            public void onChanged(Integer integer) {
                finish();
            }
        });
    }

    @Override
    protected int layoutId() {
        return R.layout.activity_system_item_detail;
    }
}